package jk;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.sql.DataSource;

import jse.dao.Cnd;
import jse.dao.Dao;
import jse.dao.Record;
import jse.ds.JseDataSource;
import jse.html.Html;
import jse.html.nodes.Document;
import jse.http.Http;
import jse.json.Json;
import jse.util.Fs;
import jse.util.JseMap;

public class Test {
	
	public static void main(String[] args) throws IOException, InterruptedException {
		String cs=Fs.read("classpath:jse.json");
		JseMap conf=Json.toMap(cs);
		DataSource ds=new JseDataSource(conf.toMap("jdbc"));
		Dao dao=new Dao(ds);
		ExecutorService service = Executors.newFixedThreadPool(24);//10是线程数
		for (int i = 1; i <=1; i++) {
			
			getPath("d:/wap/"+i+"/0.html").stream().filter(p->p.getFileName().toString().endsWith(".html")).forEach(p->{
				Document doc=Html.parse(Fs.read(p.toFile()));
				
				List<String> imgs=new ArrayList<>();//图片集合
				doc.select(".cx-hb>img").forEach(x->{
					if(!x.hasClass("download")) {
						imgs.add(x.attr("src"));
					}
				});
				String img=imgs.get(0);//图片
				String price=doc.select(".color-red").text();//参考价格
				System.err.println(price);
			});
			
		}
	}
	
	/**
	 * 
	 * @param path $
	 * @return
	 */
	public static Set<Path> getPath(String path) {
		File $file=new File(path);
		if($file.exists())
		try(Stream<Path> lists = Files.find($file.toPath(), Integer.MAX_VALUE, (p,a)->{
			return true;
		}, FileVisitOption.FOLLOW_LINKS)){
			Set<Path> al = lists.collect(Collectors.toCollection(LinkedHashSet::new));
			return al;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
		}
		return new LinkedHashSet<Path>();
	}
}
